//商品分类全局组件小仓库
import { defineStore } from "pinia";
import { reqC1 ,reqC2,reqC3} from "@/api/product/attr";
import { CategoryResopnseData } from "@/api/product/attr/type";
import {CategoryState} from "./types/type"
let useCategoryStore=defineStore('Category',{
    state: (): CategoryState=>{
        return{
            //存储一级分类数据
            c1Arr:[],
            //存储一级分类id
            c1Id:'',
            //存储二级分类的数据
            c2Arr: [],
            //存储二级分类id
            c2Id: '',
            c3Arr: [],
            c3Id: '',
        }   
    },
    actions: {
        async getC1(){
            let result: CategoryResopnseData= await reqC1();
            console.log("获取一级分类数据")
            console.log(result);
            if(result.code==200){
                this.c1Arr=result.data;
            }
        },
        //获取二级分类的数据
        async getC2(){
            let result: CategoryResopnseData= await reqC2(this.c1Id);
            console.log("二级分类的数据");
            console.log(result);
            if(result.code==200){
                this.c2Arr=result.data;
            }
        },
        //获取三级分类的数据
        async getC3(){
            let result: CategoryResopnseData=await reqC3(this.c2Id);
            console.log("三级分类数据")
            console.log(result);
            if(result.code==200){
                this.c3Arr=result.data;
            }
        }


    },
    getters: {

    }
})

export default useCategoryStore